#!/bin/sh
[ $# -gt 0 ] || { echo -e "MOVE this file to root folder and use themes dir, generate src/packed.go\nUsage: $0 <path>... > packed.go \n# path is themes dir, packed.go is file to write in"; exit 1; }

cat <<!
// THIS FILE IS AUTO GEN BY helper shell script, SEE FILE: ../helper-scripts/pack-to-src-packed-go.sh
package go_ttyping

import "encoding/base64"

func ReadPackedFile(path string) []byte {
	if b,ok := PackedFiles[path]; !ok {
		return nil
	} else {
		b, err := base64.StdEncoding.DecodeString(b) 
		if err != nil {
			panic(err)
		}

		return b
	}
}
!

printf "var PackedFiles = map[string]string{\n"
find "$@" -type f|while read f; do
	printf "\t\"$f\": \""
	openssl base64 -A < "$f"
	printf "\",\n"
done
printf "}"
